<?php

            if($form_Content == "通知")
            {
            $mc->delete($fromUsername . "_page", 0);
            $mc->set($fromUsername . "_page", "0", 0, 600);
            }
            $mc->set($fromUsername . "_do", "通知", 0, 600);
            
            $f = new SaeFetchurl();
            $blog = $f->fetch("http://jr12.blog.163.com/rss");
            if($f->errno() == 0)
            {
                preg_match_all("/\<link\>(.*?)\<\/link\>/",$blog,$link);//获取link标签
                preg_match_all("/\<title\>(.*?)\<\/title\>/",$blog,$title);//获取title标签

            }
            
            $max =((sizeof($link[0]))-2);//获取文章篇数          
            if ($max % 5)
            {
                $PageCount = ( ($max - ($max % 5) ) /5 ) + 1; //得到页码数
            }
            else
            {
                $PageCount = $max/5; //得到页码数
            }


            $LastPage = $mc->get($fromUsername . "_page");

            if ((($form_Content == "n") || ($form_Content == "N")) && $PageCount == $LastPage)//判断是不是最后一页了
            {
                $resultStr = sprintf($imageTpl, $fromUsername, $toUsername, /* $title */ "上面的已经是最后一页了", /* $Description */ "不要在往下翻啦！", /* $PicUrl */ "http://i5.3conline.com/images/piclib/201002/12/batch/1/55243/1265965093578mue0odu9ma.jpg", /* $url */ "http://i5.3conline.com/images/piclib/201002/12/batch/1/55243/1265965093578mue0odu9ma.jpg");
                echo $resultStr;
                exit();
            }
            if (($form_Content == "通知") && $LastPage == 0)
                $mc->set($fromUsername . "_page", "1", 0, 600);//设置页码数
            if ((($form_Content == "n") || ($form_Content == "N")) && $LastPage != 0)
                $mc->set($fromUsername . "_page", "".($LastPage+1)."", 0, 600);//设置页码数
            $NowPage = $mc->get($fromUsername . "_page");


            if ($NowPage == $PageCount) 
                if(!($max % 5))
                	$ArticleCount = 5;
                else
                	$ArticleCount = $max % 5;
            if ($NowPage != $PageCount)
                $ArticleCount = 5;
          
            $resultStr = 
                	"<xml>
                    <ToUserName> <![CDATA[$fromUsername]]></ToUserName>
                    <FromUserName><![CDATA[$toUsername]]></FromUserName>
                    <CreateTime>" . time() . "</CreateTime>
                    <MsgType><![CDATA[news]]></MsgType>
                    <ArticleCount>" . ($ArticleCount + 2) . "</ArticleCount>
                    <Articles>   ";
            
            $resultStr .= 
                	"<item>
					<Title><![CDATA[随时随地获取最新通知]]></Title> 
					<Description> <![CDATA[]]></Description>
          			<PicUrl>
           				<![CDATA[http://b276.photo.store.qq.com/psb?/V12pXQU74Enh4e/xK0Du2FACOsvxS7QMM07Uet7x3THirdkPlQAPCddqik!/b/dJakkaS2HAAA&bo=iwHcAAAAAAADAHM!&rf=photoDetail]]></PicUrl>
          			<Url>
          				<![CDATA[]]></Url>
          			</item>";
	
            for ($times = (($LastPage * 5) + 2); $times <(($LastPage * 5) + $ArticleCount+2); $times++) 
            {
                $link [0][$times]=strip_tags($link [0][$times]);
             
                $title[0][$times]=rtrim($title[0][$times],"]]></title>");
                $title[0][$times]=substr($title[0][$times],16,strlen($title[0][$times]));
                
                 $title[0][$times]=($times-1)."、".$title[0][$times];
                $mc->set("title", $title[0][$times], 0, 600);
                $num=explode('/',$link[0][$times]);      
                $Url="http://scnuzs.sinaapp.com/function/NoticItem.php?link=".$num[5];
                $resultStr .=
          			"<item>
                  	<Title><![CDATA[". $title[0][$times]."]]></Title>
          			<Description> <![CDATA[]]></Description>
          			<PicUrl>
          			<![CDATA[]]></PicUrl>
                    <Url>
          			<![CDATA[".$Url."]]>
                                //
                                //</Url>
          			</item>";
            }

            $resultStr .= "
          			<item>";
            if ($ArticleCount == 5)
                $resultStr .= " <Title><![CDATA[现在是第:" . $NowPage . "页\n共" . $PageCount . "页 \n下一页（回复【N】)\n回复【菜单】返回主页]]> </Title>";
            else
                $resultStr .= " <Title><![CDATA[现在是最后一页了！\n回复【菜单】返回首页]]> </Title>";
            $resultStr .= 
          			"<Description> <![CDATA[]]></Description>
          			<PicUrl><![CDATA[]]></PicUrl>
          			<Url><![CDATA[]]></Url>
          			</item>";

            $resultStr .= "
          			</Articles><FuncFlag>0</FuncFlag></xml>";
            echo $resultStr;
            exit;




?>